package com.example.administrator.testproject.Tag;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.example.administrator.testproject.R;

import java.util.List;

/**
 * Created by shengfh on 2018/2/28.
 */

public class TagListViewAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> mData;

    public TagListViewAdapter(Context mContext, List<String> mData) {
        this.mContext = mContext;
        this.mData = mData;
    }
    public void setData(List<String> data){
        this.mData.addAll(data);
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView= LayoutInflater.from(mContext).inflate(R.layout.item_tag,null);
            holder=new ViewHolder();
            holder.tagTextView=convertView.findViewById(R.id.tag_text);
            convertView.setTag(holder);
        }
        holder= (ViewHolder) convertView.getTag();
        TagUtils tagUtils = new TagUtils();

        holder.tagTextView.builder()
                .addFlagText("sss", Color.BLUE,true, Gravity.LEFT)
                .setContentText(mData.get(position))
                .build();
        return convertView;
    }
    class ViewHolder{
        TagTextView tagTextView;
    }
}
